<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>day06_demo02</title>
<script>
	//1.String对象(查手册)    
	//2.Number对象	
	var n=3.1415926;
	console.log(n.toFixed(3));//自动进位（四舍五入）
	console.log(n.toFixed(8));
	
	//3.Array对象
		//<js中数组都是object数组>
		//3.1 如何创建数组()
			//1).已知数组
			var a1=["zhangsan",25,false];
			console.log(a1[0]);
			console.log(a1[1]);
			console.log(a1[2]);
			//2).未知数据
			var a2=new Array();
			a2.push("lisi");
			a2.push(28);
			a2.push(true);
			console.log(a2[0]);
			//结论:任何方式创建的数组本质是一样的.
			
		//3.2 数组倒转的方法:
			var arr=[34,56,1,13,121,23,45,65];
			arr.reverse();
			console.log(arr);
		//3.3 数组的排序:(默认给数组排序,是按照字符串排序的)
			arr.sort();
			console.log(arr);
			//结果:[1, 121, 13, 23, 34, 45, 56, 65]

			//function x(a,b){return a-b;}
			//arr.sort(x);
			
			arr.sort(function(a,b){
				return a-b;
			});
			//sort()括号内为匿名函数,没有函数名,
			//只有函数参数,只在sort内使用,不会复用.
			console.log(arr);
			
		//4.Math对象
		
		//5.Date
			//5.1 如何创建日期
			var d1=new Date();
			var d2=new Date("2017/1/09 11:11:11");
			console.log(d1);
			console.log(d2);
			//5.2 将日期转为本地时间格式的字符串
			console.log(d1.toLocaleDateString());
			console.log(d2.toLocaleTimeString());
			console.log(d2.toLocaleString());
			//5.3读取时间分量
			var y=d1.getFullYear();
			var m=d1.getMonth()+1;
			var d=d1.getDate();
			var today=y+"年"+m+"月"+d+"日";
			console.log(today);
			
		//6.RegExp对象
			//6.1 如何创建正则对象;
			var str="you can you up,no can no bb.";
			var reg=/no/;
			
			//6.2 test():检测字符串中是否包含与reg相匹配的子串.
			console.log(reg.test(str));
			
			//6.3 exec():
				//(1)普通模式:从str中找出和正则(reg)
					//相匹配的第一个子串.
				//	console.log(reg.exec(str));
					
				//(2)全局模式:第N次调用,则从str中找出和reg相
					//匹配的第N个子串
				reg=/no/g;
				console.log(reg.exec(str));
				//结果:["no", index: 15, input: "you can you up,no can no bb."]
				console.log(reg.exec(str));
				//结果:["no", index: 22, input: "you can you up,no can no bb."]
				console.log(reg.exec(str));
				//结果:null
				console.log(reg.exec(str));
				//结果:["no", index: 15, input: "you can you up,no can no bb."]
				console.log(reg.exec(str));
				//结果:["no", index: 22, input: "you can you up,no can no bb."]
				console.log(reg.exec(str));
				//结果:null
				console.log(reg.exec(str));
				//结果:["no", index: 15, input: "you can you up,no can no bb."]
				console.log(reg.exec(str));
				//结果:["no", index: 22, input: "you can you up,no can no bb."]
		
				
		//  &&和&
			console.log(true&&false);//结果:false
			console.log(true&&3);//结果:3
			console.log(true&false);//结果:0
			console.log(true&3);//结果:1
				
		//7.function对象
			function sum(){
				var s=0;
				if(arguments.length){
					for(var i=0;i<arguments.length;i++){
						s+=arguments[i];
					}
				}
				return s;
			}
			
			//页面加载时,直接调用函数sum();
			console.log("sum1="+sum(1,2,3));
			console.log("sum2="+sum(1,3,5,6,8,45,6));
			
			
			
			
			
			
			
</script>

</head>
<body>
	<p>用来演示js内置对象</p>

</body>
</html>